<?php

/**
 * This is the model class for table "ab_customers".
 *
 * The followings are the available columns in table 'ab_customers':
 * @property integer $customer_id
 * @property string $customer_unit
 * @property string $customer_info
 * @property string $customer_billing_add
 * @property string $customer_source
 * @property integer $customer_status
 */
class Customers extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Customers the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ab_customers';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('customer_status', 'numerical', 'integerOnly'=>true),
			array('customer_unit, customer_info, customer_billing_add', 'length', 'max'=>255),
			array('customer_source', 'length', 'max'=>50),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('customer_id, customer_unit, customer_source, customer_status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		'contacts'=>array(self::HAS_MANY, 'CustomerContacts', 'customer_id' ));
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'customer_id' => '编号',
			'customer_unit' => '客户单位',
			'customer_info' => '客户简介',
			'customer_billing_add' => '客户地址',
			'customer_source' => '信息来源',
			'customer_status' => '当前状态',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('customer_id',$this->customer_id);
		$criteria->compare('customer_unit',$this->customer_unit,true);
		$criteria->compare('customer_info',$this->customer_info,true);
		$criteria->compare('customer_billing_add',$this->customer_billing_add,true);
		$criteria->compare('customer_source',$this->customer_source,true);
		$criteria->compare('customer_status',$this->customer_status);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	public function getCustomerStatus()
	{
		return array('0'=>'未激活','1'=>'激活',);
	}
	public function getCustomerStatusText()
	{
		$array=$this->getCustomerStatus();
		return $array[$this->customer_status];
	}
}